package com.fy.sys.controller;

import com.fy.core.vo.ApiRest;
import com.fy.sys.entity.DictData;
import com.fy.sys.entity.DictType;
import com.fy.sys.service.DictTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 字典类型表 前端控制器
 * </p>
 *
 * @author hxd
 * @since 2023-06-14
 */
@RestController
@RequestMapping("/dictType")
@CrossOrigin
public class DictTypeController {

    @Autowired
    private DictTypeService dictTypeService;

    @GetMapping("/findDictTypeNames")
    public ApiRest<List<DictType>> findDictTypeNames() {
        return ApiRest.success(dictTypeService.list());
    }


    @PostMapping("/addDictType")
    public ApiRest addDictType(@RequestBody DictType dictType){
        dictTypeService.add(dictType);

        return ApiRest.success("添加成功","");
    }

    @PostMapping("/findAllDictType")
    public ApiRest<List<DictType>> findAll(String dictType){
        return  ApiRest.success(dictTypeService.findAll(dictType));
    }

    @PostMapping(value = "/updateDictType")
    public ApiRest<Object> updateDictType(@RequestBody DictType dictType) {

        dictTypeService.updateById(dictType);
        return ApiRest.success("deleted successfully","");
    }

    @PostMapping(value = "/updateStatusAndType")
    public ApiRest<Object> updateStatus(Long dictId) {
        dictTypeService.updateByStatus(dictId);
        return ApiRest.success("状态修改成功","");
    }

    @PostMapping(value = "/deleteDictType")
    public ApiRest<Object> deleteDictType(Long dictId) {
        dictTypeService.deleteDictType(dictId);
        return ApiRest.success("删除成功","");
    }


    @PostMapping(value = "/batchDeleteType")
    public ApiRest<Object> batchDelete(@RequestBody List<DictType> dictTypes){
        dictTypeService.batchDeleteType(dictTypes);
        return ApiRest.success("batchDelete successfully","");
    }

}

